package gui;


import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;

import javax.swing.JPanel;

import pack.help.Command;
import pack.model.Animator;
import pack.model.Robot;
import pack.model.controllers.*;
// This is the panel that runs the simulator
public class Simulator extends JPanel {
	
	private Robot idealRobot;
	private ArrayList<Robot> robots = new ArrayList<Robot>();
	// Replica of the current command
	private Command command;
	
	
	private static final long serialVersionUID = 1L;
	
	public void newCommand(Command c){
		command = c;
		// starts a new thread which executes the given command on the given robot
		(new Thread(new Animator(command,robots,idealRobot,this))).start();
	}
	/*
	public Robot getRobot(int i){
		return robot;
	}
	*/
	public void paint(Graphics g){
		
		// DRAWING THE BACKGROUND
		// pale turqoise
		//g.setColor(new Color(175,238,238));
		int gap = 5;
		g.setColor(Color.BLACK);
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
		g.setColor(new Color(0.9f,0.9f,0.9f));
		g.fillRect(gap, gap, this.getWidth()-gap*2, this.getHeight()-gap*2);
		
		// DRAWING THE ROBOTS
		idealRobot.draw(g);
		for (Robot rob:robots){
			rob.draw(g);
		}
		
	}
	
	public Simulator() {
		idealRobot = new Robot(Color.BLACK,"ideal",new NullController());
		robots.add(new Robot(Color.RED,"PID", new PIDController()));
		//robots.add(new Robot(Color.BLUE,"PT", new PTController()));
		
		
	}

}
